package  
{
	import net.flashpunk.tweens.misc.VarTween;
	import net.flashpunk.World;
	import net.flashpunk.Tween;
	import net.flashpunk.graphics.Image;
	import net.flashpunk.FP;
	import net.flashpunk.Sfx;
	/**
	 * ...
	 * @author Donatello
	 */
	public class CutScene extends World
	{
		
		[Embed(source = "sfx/GunfireInCrowd.mp3")] private static const FIRE_CROWD:Class;
		private var fireCrowd:Sfx;
		[Embed(source = "sfx/FemaleScream.mp3")] private static const SCREAM:Class;
		private var scream:Sfx = new Sfx(SCREAM);
		
		
		private var music1:Music2;
		
		[Embed(source = "img/restauranteAfter0.png")]	private const IMG1:Class;
		[Embed(source = "img/restauranteAfter1.png")]	private const IMG2:Class;
		[Embed(source = "img/restauranteAfter2.png")]	private const IMG3:Class;
		
		
		private var img1:Image;
		private var img2:Image;
		private var img3:Image;
		
		private var tween1:VarTween;
		private var tween2:VarTween;
		private var tween3:VarTween;
				
		private var counter:int = 0;
		private var time:Number = 00;
		
		private var texto1:Boolean = false;
		private var texto2:Boolean = false;

		private var music:Music = new Music;
		
		public function CutScene() 
		{
			music.stop();
			
			fireCrowd= new Sfx(FIRE_CROWD);
			music1 = new Music2();
			
			img1 = new Image(IMG1);
			img1.alpha = 0;
			img2 = new Image(IMG2);
			img2.alpha = 0;
			img3 = new Image(IMG3);
			img3.alpha = 0;
						
			
			tween1 = new VarTween();
			tween2 = new VarTween();
			tween3 = new VarTween();
						
			addGraphic(img1);
			addTween(tween1);
			addGraphic(img2);
			addTween(tween2);
			addGraphic(img3);
			addTween(tween3);
			
			music1.play();
			

		}
		
		override public function begin():void
		{
			tween1.tween(img1, "alpha", 1, 7);
		}
		
		
		
		override public function update():void
		{
			time+= FP.elapsed;
				
			if (tween1.percent<0.2 && counter==0)
			{	
				if(!fireCrowd.playing)
					fireCrowd.play();
			}
			if (tween1.percent == 1 && counter==0)
			{
				counter += 1;
				tween1.tween(img1, "alpha", 0, 1);
				tween2.tween(img2, "alpha", 1, 7);
			}
			if (tween2.percent == 1 && counter==1)
			{
				counter += 1;
				tween2.tween(img2, "alpha", 0, 1);
				time = 0.0;
				if(!texto1)
				add(new Dialog("Vi el miedo en sus ojos", 300, 300,2, 300));
				texto1 = true;
			}
			
			if(time>=3 && counter==2)
			{
				counter += 1;
				time = 0.0;
				if(!texto2)
					add(new Dialog("No pude salvarla", 300, 300, 2, 300));
				texto2 = true;
			}
			
			if(time>=3 && counter==3)
			{	
				scream.play();
				tween3.tween(img3, "alpha", 1, 7);
				counter += 1;
				time = 0.0;
			}
			
			if (tween3.percent == 1 && counter==4)
			{
				counter += 1;
				tween3.tween(img3, "alpha", 0, 1);
				add(new Dialog("Ahora solo quiero venganza", 300, 300,3, 300));
				time = 0.0;
			}
			
			if (time >= 3 && counter == 5)
			{
				FP.world = new SixScene();
				removeAll();
			}
				
				
			super.update();
		}
		
	}

}